package com.egg.ylt.controls;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.egg.ylt.R;
import com.ruffian.library.widget.RTextView;

/**
 * author:        yupeng
 * created on:    2019/3/4 18:36
 * description:   优惠券弹窗
 */
public class DIALOG_CouponTip extends PopupWindow {
    private LinearLayout rootLayout;
    private LinearLayout popLayout;
    private RTextView confirmButton;

    public DIALOG_CouponTip(@NonNull Context context) {
        super(context);
        rootLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.dialog_coupon_tip, null);
        popLayout = rootLayout.findViewById(R.id.pop_layout);
        confirmButton = rootLayout.findViewById(R.id.confirm_button);

        // 设置SelectPicPopupWindow的View
        this.setContentView(rootLayout);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setTouchable(true);
        this.setOutsideTouchable(true);  //设置点击屏幕其它地方弹出框消失
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        // 设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);

        // rootLayout父布局 popLayout子布局
        // rootLayout 添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        rootLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        popLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });

        confirmButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    public void show() {
        this.showAtLocation(rootLayout, Gravity.CENTER, 0, 0);
    }
}
